﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace LaughingDog
{
    /// <summary>
    /// Enumeration of all debug output types for logging.
    /// </summary>
    public enum DebugOutputTypes { Standard, Warning, Error }

    public delegate void OnDebugOutputEventHandler(DebugOutputTypes outputType, String message);

    /// <summary>
    /// Static class that should be used for all debug functions.
    /// </summary>
    public static class Debug
    {
        /// <summary>
        /// Hook up to this if you wish to output debug messages to your own handler.
        /// </summary>
        public static OnDebugOutputEventHandler OnDebugOutput;

        /// <summary>
        /// Gets a value indicating whether the current game is running in Debug or Release.
        /// </summary>
        public static Boolean IsDebugBuild { get { return isDebugBuild(); } }

        /// <summary>
        /// Gets a value indicating whether the current game is running in Release or Debug.
        /// </summary>
        public static Boolean IsReleaseBuild { get { return !isDebugBuild(); } }

        /// <summary>
        /// Logs a message to the LaughingDog Console.
        /// </summary>
        /// <param name="message">The message to log.</param>
        public static void Log(String message)
        {
            ouputMessage(DebugOutputTypes.Standard, message);            
        }

        /// <summary>
        /// Logs a message to the LaughingDog Console.
        /// </summary>
        /// <param name="message">The message to log.</param>
        /// <param name="context"></param>
        public static void Log(String message, object context)
        {
            ouputMessage(DebugOutputTypes.Standard, message);
        }

        /// <summary>
        /// Logs a warning message to the LaughingDog Console.
        /// </summary>
        /// <param name="message">The message to log.</param>
        public static void LogWarning(String message)
        {
            ouputMessage(DebugOutputTypes.Warning, message);
        }

        /// <summary>
        /// Logs a warning message to the LaughingDog Console.
        /// </summary>
        /// <param name="message">The message to log.</param>
        /// <param name="context"></param>
        public static void LogWarning(String message, object context)
        {
            ouputMessage(DebugOutputTypes.Warning, message);
        }

        /// <summary>
        /// Logs an error message to the LaughingDog Console.
        /// </summary>
        /// <param name="message">The message to log.</param>
        public static void LogError(String message)
        {
            ouputMessage(DebugOutputTypes.Error, message);
        }

        /// <summary>
        /// Logs an error message to the LaughingDog Console.
        /// </summary>
        /// <param name="message">The message to log.</param>
        /// <param name="context"></param>
        public static void LogError(String message, object context)
        {
            ouputMessage(DebugOutputTypes.Error, message);
        }

        /// <summary>
        /// 
        /// </summary>
        public static void Break()
        {
            #if DEBUG
                System.Diagnostics.Debugger.Break();
            #endif
        }

        private static Boolean isDebugBuild()
        {
            #if DEBUG
                return true;
            #else
                return false;
            #endif
        }

        private static void ouputMessage(DebugOutputTypes outputType, String message)
        {
            if (OnDebugOutput != null) OnDebugOutput(outputType, message);

            switch (outputType)
            {
                case DebugOutputTypes.Standard:
                    System.Console.WriteLine("Log: " + message);
                    break;
                case DebugOutputTypes.Warning:
                    System.Console.WriteLine("Warning: " + message);
                    break;
                case DebugOutputTypes.Error:
                    System.Console.WriteLine("Error: " + message);
                    break;
                default:
                    break;
            }            
        }
    }
}
